package org.skyfree.ghyll.tcard.progress;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Tree;

public class SelectCellEditor extends CellEditor implements SelectionListener 
{
	Button button;
	public SelectCellEditor(Tree tree) 
	{
		super(tree);
	}

	@Override
	protected Control createControl(Composite parent) 
	{
		button = new Button(parent, SWT.NONE);;
		button.setFont(parent.getFont());
		button.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
		button.setBackgroundImage(Activator.getImageDescriptor("icons/checkbox2.jpg").createImage());
		this.button.addSelectionListener(this);
		return this.button;
	}

	@Override
	protected Object doGetValue() 
	{
		return Boolean.valueOf(this.button.getSelection());
	}

	@Override
	protected void doSetFocus() 
	{
		this.button.setFocus();
		
	}

	@Override
	protected void doSetValue(Object value) 
	{
		this.button.setSelection(((Boolean)value).booleanValue());
		
	}

	@Override
	public void widgetDefaultSelected(SelectionEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void widgetSelected(SelectionEvent e) 
	{
		this.deactivate();
		
	}
	
	
}
